<form method="post" action="/action/recipe_edit" onsubmit="return onSubmit(this);" enctype="multipart/form-data">
<input type="hidden" name="recipeName" value="{!$recipe.name|default:$recipeName!}"/>
<input type="hidden" name="recipeId" value="{!$recipe.recipeId|default:0!}"/>
{!*用来检验是否在客户端对菜谱名称进行过恶意的修改*!}
<input type="hidden" name="checkCode" value="{!$checkCode!}"/>
<table cellspacing="0" cellpadding="4" border="0" width="100%">
	<tr>
		<td width="80" class="r">菜谱名称</td>
		<td>{!$recipe.name|default:$recipeName!}</td>
	</tr>
	<tr>
		<td class="r">图片</td>
		<td>{!if $typeId==1!}<img src="/static/picture/recipe/{!$recipe.recipeId!}_square" class="square"/>{!/if!}<input type="file" name="picture" size="40"/></td>
	</tr>
	<tr>
		<td valign="top" class="r">菜谱用料</td>
		<td><textarea name="ingredients" style="width:400px;height:140px">{!$recipe.ingredients!}</textarea></td>
	</tr>
	<tr>
		<td valign="top" class="r">菜谱做法</td>
		<td><textarea name="directions" style="width:400px;height:140px">{!$recipe.directions!}</textarea></td>
	</tr>
	<tr>
		<td valign="top" class="r">小帖士</td>
		<td><textarea name="skill" style="width:400px;height:140px">{!$recipe.skill!}</textarea>可不填</td>
	</tr>
	<tr>
		<td valign="top" class="r">简介</td>
		<td><textarea name="description" style="width:400px;height:140px">{!$recipe.description!}</textarea>300字以内</td>
	</tr>
	<tr>
		<td class="r">制作时间</td>
		<td><input type="text" name="makeTime" style="width:200px;" maxlength="15"/></td>
	</tr>
	<tr>
		<td class="r">难度</td>
		<td><select name="difficulty">
			<option value="1" {!if $recipe.difficulty==1!}selected{!/if!}>1</option>
			<option value="2" {!if $recipe.difficulty==2!}selected{!/if!}>2</option>
			<option value="3" {!if $recipe.difficulty==3!}selected{!/if!}>3</option>
			<option value="4" {!if $recipe.difficulty==4!}selected{!/if!}>4</option>
			<option value="5" {!if $recipe.difficulty==5!}selected{!/if!}>5</option>
		</select></td>
	</tr>
	<tr>
		<td class="r">标签</td>
		<td><input type="text" name="tags" style="width:400px;" maxlength="40"/></td>
	</tr>
	<tr>
		<td></td>
		<td>
			<input type="submit" value="确定"/>
			<input type="reset" value="取消"/>
		</td>
	</tr>
</table>
</form>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript">
function onSubmit(form){
	if (!/^([a-zA-Z\u4e00-\u9fa5()（）]+\d+克\s*)+$/.test($.trim(form.ingredients.value))) {
		alert('菜谱用料格式不正确');
		form.ingredients.focus();
		return false;
	}
	
	if (!$.trim(form.directions.value)) {
		alert('菜谱做法不能为空');
		form.directions.focus();
		return false;
	}
	var desc = $.trim(form.description.value);
	var len = desc.replace(/[\u4e00-\u9fa5]/g,'aa').length;
	if (len < 40 || len >600) {
		alert('简介长度必须在20至300字之间');
		form.description.focus();
		return false;
	}
	return true;
}
initForm();
function initForm() {
	var f = document.forms[1];
	smart(f.ingredients, '酱油 1汤匙\n醋   2茶匙\n糖   3汤匙');
	smart(f.directions, '1. 先做这个...\n2. 后做这个...\n3. 等等...');
	smart(f.skill, '有什么需要特别注意的吗？');
	smart(f.description, '这个菜谱总的来说有些什么特点，或者功效，或者有意思的来源，都可以介绍一下。');
}

function focus(){
	this.value='';
	this.className = '';
}
function smart(el,def) {
	if (!$.trim(el.value)) {
		el.className = 'hint';
		el.value=def;
		el.onfocus=focus;		
		el.onblur = function(){
			if (this.value == '') {
				this.value = def;
				this.className = 'hint';
				el.onfocus=focus;
			} else {
				el.onfocus=function(){};
			}
		};
	}
	
}	
</script>